package com.ymatou.iapi.productquery.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productprice.parameter.ProductAllPriceBean;
import com.ymatou.iapi.productquery.parameter.CatalogList.ProductInCartBean;
import com.ymatou.iapi.productquery.service.GetCatalogListByDeliveryExtraCall;
import com.ymatou.iapi.productquery.service.GetCatalogListByDeliveryExtraIsolationCall;
import com.ymatou.iapi.sellerproduct.service.ChangeNewProductInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ActivityPoolService;
import com.ymttest.business.service.AdminCallService;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.ProductPriceCallService;
import com.ymttest.business.service.ProductQueryCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;

public class Ts_GetCatalogListByDeliveryExtra {
	private static GetCatalogListByDeliveryExtraCall getCatalogListByDeliveryExtraCall = new GetCatalogListByDeliveryExtraCall();
	private static GetCatalogListByDeliveryExtraIsolationCall getCatalogListByDeliveryExtraIsolationCall = new GetCatalogListByDeliveryExtraIsolationCall();
	
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	private static String sellerName = EnvSetup.getData("productpriceSellerName");	
	
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
	
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("非交易隔离查询接口, 多物流购物车中商品列表");
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getCatalogListByDeliveryExtraCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	

	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCatalogListByDeliveryExtra_001() {
		Logger.start(true,"普通单规格商品，普通单规格直播商品 查询");
		try {
			//发布商品
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc2.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID", sellerId,"LoginID", sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			
			//收集catalogs
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,true);
			
			
			//================================================================================
			//加入直播
			int liveId = LiveCallService.createLiveInProgress(sellerName, Integer.valueOf(sellerId)).getJSONObject("Data").getInt("ActivityId");
			SellerProductCallService.addProductInLive(sellerId, liveId, productId);
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,liveId,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,liveId,true);
			
			
			
			//================================================================================
			//结束直播
			LiveCallService.closeLive(liveId, Integer.valueOf(sellerId));
		
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
			
			//================================================================================
			//加入未开始直播
			liveId = LiveCallService.createLiveBeginInFuture(sellerName, Integer.valueOf(sellerId)).getJSONObject("Data").getInt("ActivityId");
			SellerProductCallService.addProductInLive(sellerId, liveId, productId);
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
		
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByDeliveryExtra_002() {
		Logger.start(true, "普通多规格商品,普通多规格直播商品 查询");
		try {
			String productId = ProductQueryCallService.getNewProduct(sellerId, sellerName);
			
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			
			//check GetCatalogListByCatalogIdList
			
			
			
			checkByCatalogs(catalogAndTypeList,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,true);
			
			//================================================================================
			//加入直播
			int liveId = LiveCallService.createLiveInProgress(sellerName, Integer.valueOf(sellerId)).getJSONObject("Data").getInt("ActivityId");
			SellerProductCallService.addProductInLive(sellerId, liveId, productId);
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,liveId,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,liveId,true);
			
			//暂停销售
			SellerProductCallService.suspendSaleProductInLive(sellerId, liveId, productId);
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
		}catch (Exception e) {
			Logger.fail(e); 
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByDeliveryExtra_003() {
		Logger.start(true, "普通活动商品查询");
		int activityId = 0;
		try {
			String productId = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation(sellerId).getProductId();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			activityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,inaid,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,inaid,0,0,true);
			
			
			//结束活动
			//activityProductsWapper.update(inaid, MapUtil.hashMap("end",YMTDateUtil.getBeforeOrNextDate(-1))); 
			AdminCallService.closeProductInActivity(String.valueOf(inaid));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
		}catch (Exception e) {
			Logger.fail(e);
		}finally{
			if (activityId>0){ActivityPoolService.removeActivityIdFromPool(activityId);}
		}
	}
	
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByDeliveryExtra_004() {
		Logger.start(true, "交易隔离活动商品查询");
		int activityId = 0;
		try {
			String productId = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndIsolation(sellerId).getProductId();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			activityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,inaid,0,0,true);
			
			
			//结束活动
			//activityProductsWapper.update(inaid, MapUtil.hashMap("end",YMTDateUtil.getBeforeOrNextDate(-1))); 
			AdminCallService.closeProductInActivity(String.valueOf(inaid));
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}finally{
			if (activityId>0){ActivityPoolService.removeActivityIdFromPool(activityId);}
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByDeliveryExtra_005() {
		Logger.start(true, "活动直播商品查询");
		try {
			String productId = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation(sellerId).getProductId();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			
			//================================================================================
			//加入直播
			int liveId = LiveCallService.createLiveInProgress(sellerName, Integer.valueOf(sellerId)).getJSONObject("Data").getInt("ActivityId");
			SellerProductCallService.addProductInLive(sellerId, liveId, productId);
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,inaid,0,liveId,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,inaid,0,liveId,true);
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCatalogListByDeliveryExtra_006() {
		Logger.start(true,"普通多规格商品，增加规格");
		try {
			//发布商品
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc10.json");	
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID", sellerId,"LoginID", sellerName));

			
			//call&获取返回报文
			JSONObject result = SellerProductCallService.addNewProduct(addProductBean);
			String productId = result.getJSONObject("Data").getString("ProductID");
			
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,true);
			
			
			String fileName = "changenewproductinfocalltpl_003.json";
			new ChangeNewProductInfoCall().callAndGetReturnData(fileName,MapUtil.hashMap("LoginID", sellerName, "UserID", sellerId,"Product->sProductId",productId,"ProductID",productId));

			catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			
			
			YMTDateUtil.waitTime(5);
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,true);
			
			

		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByCatalogIdList_007() {
		Logger.start(true, "普通下一场会员活动商品查询");
		int activityId = 0;
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,productId,MapUtil.hashMap("ActivityTemplateId", 1));
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
				

			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productId, MapUtil.hashMap("nbuyer",true,"isolation",false));
			}
			
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			activityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,inaid,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,inaid,0,true);
			
			
			//结束活动
			//activityProductsWapper.update(inaid, MapUtil.hashMap("end",YMTDateUtil.getBeforeOrNextDate(1))); 
			AdminCallService.closeProductInActivity(String.valueOf(inaid));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
		}catch (Exception e) {
			Logger.fail(e);
		}finally{
			if (activityId>0){ActivityPoolService.removeActivityIdFromPool(activityId);}
		}
	}
	


	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByCatalogIdList_007_001() {
		Logger.start(true, "多个商品 普通下一场会员活动商品查询");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,productId,MapUtil.hashMap("ActivityTemplateId", 1));
			String catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0).getsCatalogId();
									
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			

			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productId, MapUtil.hashMap("nbuyer",true,"isolation",false));
			}
			
			
			String productId2 = ProductPriceCallService.getProductIdWithAllPrice();
			ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,productId2,MapUtil.hashMap("ActivityTemplateId", 1));
			String catalogs2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId2).get(0).getsCatalogId();
									
			int inaid2 = Integer.parseInt(activityProductsWapper.getByProdId(productId2).get("inaid").toString());
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productId, MapUtil.hashMap("nbuyer",true,"isolation",false));
			}
			
			
			JSONObject ret = getCatalogListByDeliveryExtraCall.search(MapUtil.hashMap(catalogs,3,catalogs2,3));
			JSONArray prodList = ret.getJSONObject("Data").getJSONArray("ProductList");
			
			//bean1 
			ProductInCartBean tgtbean = ProductQueryCallService.getProductInCartForDeliveryBean(catalogs,3,0,inaid,0);
			ProductInCartBean actBean = ProductQueryCallService.getBeanFromJson(prodList.getJSONObject(0),ProductInCartBean.class);
			
			
			//bean2
			ProductInCartBean tgtbean2 = ProductQueryCallService.getProductInCartForDeliveryBean(catalogs2,3,0,inaid2,0);
			ProductInCartBean actBean2 = ProductQueryCallService.getBeanFromJson(prodList.getJSONObject(1),ProductInCartBean.class);
			
			List<ProductInCartBean> tgtBeanList = Arrays.asList(tgtbean,tgtbean2);
			List<ProductInCartBean> actBeanList = Arrays.asList(actBean,actBean2);
			
			tgtBeanList.forEach(ele->{
				ProductInCartBean tmp=actBeanList.stream().filter(x->x.getCatalogId().equals(ele.getCatalogId())).findFirst().orElse(null);
				Logger.verifyNotNull(tmp, "期待结果不应为null:catalogid:" +ele.getCatalogId());
				ProductQueryCallService.compareProductInCartForDeliveryBean(ele, tmp,  "检查 GetCatalogListByCatalogIdList");
			});
			
			
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByCatalogIdList_008() {
		Logger.start(true, "交易隔离下一场活动商品查询");
		int activityId = 0;
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,productId,MapUtil.hashMap("ActivityTemplateId", 1));
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
			

			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productId, MapUtil.hashMap("nbuyer",true,"isolation",true));
			}
			
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			activityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,inaid,0,true);
			
			
			//结束活动
			//activityProductsWapper.update(inaid, MapUtil.hashMap("end",YMTDateUtil.getBeforeOrNextDate(1))); 
			AdminCallService.closeProductInActivity(String.valueOf(inaid));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,0,0,0,true);
			
		}catch (Exception e) {
			Logger.fail(e);
		}finally{
			if (activityId>0){ActivityPoolService.removeActivityIdFromPool(activityId);}
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByCatalogIdList_010() {
		Logger.start(true, "普通活动商品查询,库存为0");
		int activityId = 0;
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation(sellerId);
			String productId =productAllPriceBean.getProductId();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
									
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			activityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,inaid,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,inaid,0,0,true);
			
			
			//活动库存为0 就移到下一场活动
			ProductPriceCallService.updateActivityStockTo0InMgo(productAllPriceBean, inaid);
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,-1*inaid,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,-1*inaid,0,0,true);
			
		}catch (Exception e) {
			Logger.fail(e);
		}finally{
			if (activityId>0){ActivityPoolService.removeActivityIdFromPool(activityId);}
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetCatalogListByCatalogIdList_011() {
		Logger.start(true, "交易隔离活动商品查询,库存为0");
		int activityId = 0;
		try {
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndIsolation(sellerId);String productId =productAllPriceBean.getProductId();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(ele->ele.getsCatalogId()).collect(Collectors.toList());
									
			int inaid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());
			activityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			List<List<String>> catalogAndTypeList = new ArrayList<>();
			catalogs.forEach(ele->catalogAndTypeList.add(Arrays.asList(ele,"3")));
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,inaid,0,0,true);
			
			
			//活动库存为0 就移到下一场活动
			ProductPriceCallService.updateActivityStockTo0InMgo(productAllPriceBean, inaid);
			
			
			//check GetCatalogListByCatalogIdList
			checkByCatalogs(catalogAndTypeList,0,0,0,false);
			
			//check GetCatalogListByTradeIsolation
			checkByCatalogs(catalogAndTypeList,-1*inaid,0,0,true);
			
		}catch (Exception e) {
			Logger.fail(e);
		}finally{
			if (activityId>0){ActivityPoolService.removeActivityIdFromPool(activityId);}
		}
	}
	
	
	
	public static void checkByCatalogs(List<List<String>> catalogAndTypeList,boolean isTradeIsolation) throws Exception{
		checkByCatalogs(catalogAndTypeList,0,0,0,isTradeIsolation);
	}
	
	

	public static void checkByCatalogs(List<List<String>> catalogAndTypeList, int prodInActivityId, int prodInNextActivityId,int liveId,boolean isTradeIsolation) throws Exception{
		//mongo库中取值
		for(int i=0;i<catalogAndTypeList.size();i++){
			List<String> catalogAndType = catalogAndTypeList.get(i);
			
			ProductInCartBean tgtbean = ProductQueryCallService.getProductInCartForDeliveryBean(catalogAndType.get(0),
								Integer.parseInt(catalogAndType.get(1)), prodInActivityId,prodInNextActivityId, liveId);
		
			
			JSONObject ret;
			String chkdesc;
			if (isTradeIsolation){
				//交易隔离接口
				ret = getCatalogListByDeliveryExtraIsolationCall.search(catalogAndType);
				chkdesc = "检查 GetCatalogListByTradeIsolation";
			}else{
				
				//普通交易不隔离接口
				ret = getCatalogListByDeliveryExtraCall.search(catalogAndType);
				chkdesc = "检查 GetCatalogListByCatalogIdList";
			}
			
			//返回码检查
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码检查");
			
			JSONArray prodList = ret.getJSONObject("Data").getJSONArray("ProductList");
			ProductInCartBean actBean = ProductQueryCallService.getBeanFromJson(prodList.getJSONObject(0),ProductInCartBean.class);
			
			//返回值比对
			ProductQueryCallService.compareProductInCartForDeliveryBean(tgtbean, actBean, chkdesc);
		}
	}
	

}
